//
//  CloudDao.m
//  ZhiNengKong_APILib
//
//  Created by 宣佚 on 14/12/29.
//  Copyright (c) 2014年 刘宣佚. All rights reserved.
//

#import "CloudDao.h"
#import "lib/ZhiNengKong_APILib.h"
#import "NSString+WebErrorCode.h"

@implementation CloudDao

/**
 *  申请手机注册验证码，对应API 1
 *
 *  @param topInfo   申请手机注册验证码上传信息
 *  @param success   成功返回 NSMutableDictionary
 *  @param failure   失败返回
 *  @param exception 异常返回
 */
+(void)GetRegisterVerityCode:(NSDictionary *)topInfo
                     success:(void (^)(id returnValue))success
                     failure:(void (^)(NSString *errorMessage))failure
                   exception:(void (^)(NSString *errorMessage))exception
{
    ZhiNengKong_APILib *cloud = [[ZhiNengKong_APILib alloc] init];
    cloud.timeInterval = 10;
    cloud.serviceURL = serviceURL;
    [cloud globalTimelinePostURL:KGetRegisterVerityCodeURL
                    HeadInfoType:HEADINFO_TYPE_ONE
                              SC:KSC
                              SV:kGetRegisterVerityCodeSV
                      parameters:topInfo
                         success:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"success:%@",returnInfo.ReturnValue);
                             success(returnInfo.ReturnValue);
                         }
                         failure:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"failure:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                             NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                             NSString *returnValue = [resultMessage ErrorCode];
                             failure(returnValue);
                         }
                    SerException:^(ZhiNengKong_APILib *returnInfo) {
                        NSLog(@"SerException:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                        NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                        NSString *returnValue = [resultMessage ErrorCode];
                        exception(returnValue);
                    }
                    NetException:^(NSInteger ErrorCode, NSError *ErrorMessage) {
                        NSLog(@"NetException:%ld - %@",(long)ErrorCode,[ErrorMessage description]);
                        if (ErrorCode == -1001) {
                            exception(@"网络请求超时");
                        } else {
                            exception(@"网络连接异常");
                        }
                    }];
}

/**
 *  验证手机注册验证码，对应API 2
 *
 *  @param topInfo   验证手机注册验证码上传信息
 *  @param success   成功返回 NSMutableDictionary
 *  @param failure   失败返回
 *  @param exception 异常返回
 */
+(void)VerityRegisterCode:(NSDictionary *)topInfo
                  success:(void (^)(id returnValue))success
                  failure:(void (^)(NSString *errorMessage))failure
                exception:(void (^)(NSString *errorMessage))exception
{
    ZhiNengKong_APILib *cloud = [[ZhiNengKong_APILib alloc] init];
    cloud.serviceURL = serviceURL;
    [cloud globalTimelinePostURL:kVerityRegisterCodeURL
                    HeadInfoType:HEADINFO_TYPE_ONE
                              SC:KSC
                              SV:kVerityRegisterCodeSV
                      parameters:topInfo
                         success:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"success:%@",returnInfo.ReturnValue);
                             success(returnInfo.ReturnValue);
                         }
                         failure:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"failure:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                             NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                             NSString *returnValue = [resultMessage ErrorCode];
                             failure(returnValue);
                         }
                    SerException:^(ZhiNengKong_APILib *returnInfo) {
                        NSLog(@"SerException:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                        NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                        NSString *returnValue = [resultMessage ErrorCode];
                        exception(returnValue);
                    }
                    NetException:^(NSInteger ErrorCode, NSError *ErrorMessage) {
                        NSLog(@"NetException:%ld - %@",(long)ErrorCode,[ErrorMessage description]);
                        if (ErrorCode == -1001) {
                            exception(@"网络请求超时");
                        } else {
                            exception(@"网络连接异常");
                        }
                    }];
}

/**
 *  手机账号注册，对应API 3
 *
 *  @param topInfo   手机账号注册上传信息
 *  @param success   成功返回 NSMutableDictionary
 *  @param failure   失败返回
 *  @param exception 异常返回
 */
+(void)RegisterUser:(NSDictionary *)topInfo
            success:(void (^)(id returnValue))success
            failure:(void (^)(NSString *errorMessage))failure
          exception:(void (^)(NSString *errorMessage))exception
{
    ZhiNengKong_APILib *cloud = [[ZhiNengKong_APILib alloc] init];
    cloud.serviceURL = serviceURL;
    [cloud globalTimelinePostURL:kRegisterUserURL
                    HeadInfoType:HEADINFO_TYPE_ONE
                              SC:KSC
                              SV:kRegisterUserSV
                      parameters:topInfo
                         success:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"success:%@",returnInfo.ReturnValue);
                             success(returnInfo.ReturnValue);
                         }
                         failure:^(ZhiNengKong_APILib *returnInfo) {
                             NSLog(@"failure:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                             NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                             NSString *returnValue = [resultMessage ErrorCode];
                             failure(returnValue);
                         }
                    SerException:^(ZhiNengKong_APILib *returnInfo) {
                        NSLog(@"SerException:%@ - %@",returnInfo.ResultMessage,returnInfo.ReturnValue);
                        NSString *resultMessage = [NSString stringWithFormat:@"%@",returnInfo.ResultMessage];
                        NSString *returnValue = [resultMessage ErrorCode];
                        exception(returnValue);
                    }
                    NetException:^(NSInteger ErrorCode, NSError *ErrorMessage) {
                        NSLog(@"NetException:%ld - %@",(long)ErrorCode,[ErrorMessage description]);
                        if (ErrorCode == -1001) {
                            exception(@"网络请求超时");
                        } else {
                            exception(@"网络连接异常");
                        }
                    }];
}

@end
